package com.example.httpclient.util;

import com.example.httpclient.handler.CustomHttpClientResponseHandler;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.ClassicHttpRequest;

import java.io.IOException;

/**
 * @author zpMeng
 * @since 8/28/2024
 */
public class ResponseHandler {

    public static CloseableHttpResponse sendRequestAndGetResponse(CloseableHttpClient client, ClassicHttpRequest request) {
        try {
            return (CloseableHttpResponse) client.execute(request, new CustomHttpClientResponseHandler());
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}
